Apache 安装SSL配置记录

Apache 安装SSL 配置记录

使用yum install mod_ssl

安装ssl模块报错 冲突

原因 默认版本与环境版本不一致

解决方法:使用yum install mod24_ssl.x86_64

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

<VirtualHost *:443>
#Created by hajnxg 2018-08-03
Serveradmin hajnxg@126.com
ServerName ssl.werty.cn
DocumentRoot /var/www/html
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
SSLHonorCipherOrder on
SSLCertificateFile /var/www/ssl/ssl/public.pem
SSLCertificateKeyFile /var/www/ssl/ssl/ssl.werty.cn.key
SSLCertificateChainFile /var/www/ssl/ssl/chain.pem

<Directory "/var/www/html">
Options FollowSymLinks
AllowOverride All
#Require all denied
Require all granted
</Directory>
</VirtualHost>

开启http 转发 https

默认情况下,apache的80端口网站目录是/var/www/html

查找配置文件并修改/etc/httpd/conf/httpd.conf

利用伪静态功能

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<Directory "/var/www/html">

# Possible values for the Options directive are "None", "All",

# or any combination of:

# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

#

# Note that "MultiViews" must be named *explicitly* --- "Options All"

# doesn't give it to you.

#

# The Options directive is both complicated and important. Please see

# http://httpd.apache.org/docs/2.2/mod/core.html#options

# for more information.

#

Options Indexes FollowSymLinks

#

# AllowOverride controls what directives may be placed in .htaccess files.

# It can be "All", "None", or any combination of the keywords:

# Options FileInfo AuthConfig Limit

#

AllowOverride All #原来是None,需要改成All

#

# Controls who can get stuff from this server.

#

Order allow,deny

Allow from all

</Directory>

然后在需要跳转的网站根目录,也就是80端口的网站根目录/var/www/html下创建一个.htaccess文件,如果目录下已经有.htaccess文件,则用vi或者其他编辑器打开,在最下面添加写入如下语句即可

1
2
3
4
5
6
7
RewriteEngine on

RewriteBase /

RewriteCond %{SERVER_PORT} !^443$

RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

保存,重启httpd服务,再次访问http://域名,发现会直接跳转到https://域名

配置成功。